/*
 * @Author: 陈天羽 7834921+woshichentianyu@user.noreply.gitee.com
 * @Date: 2022-05-12 09:41:38
 * @LastEditors: 陈天羽 7834921+woshichentianyu@user.noreply.gitee.com
 * @LastEditTime: 2022-05-20 23:21:35
 * @FilePath: \bilibiliInterface_shiping_one_node\main.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
const express = require('express')

const app = express()

const cors = require('cors')
app.use(cors(
))
app.use('/public',express.static('public'))
app.use('/userInfo',express.static('userInfo'))

const fs = require('fs')
const buffer = require('node:buffer')

const http = require('http')
const https = require('https')

// let uid = 13805897 //我的uid
// let uid = 7966 //花玲的uid
// let uid = 269415357 //花花Haya的uid
/* https.get(`https://api.bilibili.com/x/relation/stat?vmid=${uid}&jsonp=jsonp`,(res)=>{
    let data = ''
    res.on('data',(chunk)=>{
        data += chunk
    })
    res.on('end',()=>{
        console.log(JSON.parse(data))

        app.get('/getUser',(req,res)=>{
            console.log('/getUser  响应了')
            res.send(JSON.parse(data))
        })
    })
}).on('error',(err)=>{
    console.log("Erorr:",err.message)
}) */

const {downloadUrl} = require('./downloadImg')
const {connection} = require('./linkMySql')
const { json } = require('body-parser')

const {getUserInfo,fileSave,insertMysql_bilibiliUserInfo_data,userInfoImageWrite,userInfoImageRead,openReadImage,
sendImage,getLiveMsg} = require('./getUserInfo')

app.get('/filesave',async(req,res)=>{
    // res.send(req.query)
    // console.log(req.query)
    // console.log(req.query.mid)
    // console.log(getUserInfo(req.query.mid))
    // getUserInfo(req.query.mid)
    // res.send(getUserInfo(req.query.mid))
    var a = await getUserInfo(req.query.mid)
    
    console.log('a:',a)
    res.send(a)
})

const url = require('url');

app.get('/getImage',async(req,res)=>{
    var openImage = await sendImage(req.query.mid)
    var adr = `http://localhost:5000${openImage.slice(1)}`
    var p = url.parse(adr,true)
    console.log(p.host)
    console.log(p.pathname) 
    console.log(p.search)
    res.send(openImage)
});

const {getHisPlayMsg,HPMsg} = require('./getUserInfo')

app.get('/getHPM',async (req,res)=>{
    let ep_id = req.query.ep_id;
    console.log(ep_id);
    const get_hpm = await getHisPlayMsg(ep_id);
    res.send(get_hpm);

})

const {
    aid,cid,bvid,fan_id,link
} = HPMsg;
app.get('/getAidD',(req,res)=>{
    let ep_id = req.query.ep_id;
    res.send(`aid:${aid}`);
    res.send(`aid:${cid}`);
    res.send(`aid:${bvid}`);
    res.send(`aid:${fan_id}`);
    res.send(`aid:${link}`);
})






app.get('/hello',(req,res)=>{
    res.send("hello Vue")
})

app.get('/getLive',async (req,res)=>{
    const a = await getLiveMsg(req.query.roomid)
    res.send(a)
})

app.listen(5000,()=>{
    console.log('5000端口已经监视')
})